package models

import (
	"fmt"
	"time"
	"xorm.io/builder"
)

type CharStandard struct {
	Id                         int       `xorm:"not null pk autoincr comment('自增主键') INT(11)"`
	SchoolId                   int       `xorm:"not null comment('驾校编号') INT(11)"`
	Seq                        int       `xorm:"not null comment('收费标准编号') TINYINT(4)"`
	Subject                    string    `xorm:"comment('培训部分及方式 1:第一部分集中教学 2:第一部分网络教学 3:第四部分集中教学 4:第四部分网络教学 5:模拟器教学 6:第二部分普通教学 7:第二部分智能教学 8:第三部分普通教学 9:第三部分智能教学') ENUM('1','2','3','4','5','6','7','8','9')"`
	TrainingCarType            string    `xorm:"not null default 'C1' comment('培训车型') ENUM('A1','A2','A3','B1','B2','C1','C2','C3','C4','C5','D','E','F','M','N','P')" form:"trainingcartype"`
	TimeDays                   string    `xorm:"default '' VARCHAR(255)"`
	TrainingTime               string    `xorm:"not null default '1' comment('培训时段 1:普通时段 2:高峰时段 3:节假日时段 9:所有时段') ENUM('1','2','3','9')"`
	TrainingMode               string    `xorm:"not null default '2' comment('培训模式 1:定时培训 2:预约培训 9:其他') ENUM('1','2','9')" form:"trainingmode"`
	ChargeMode                 string    `xorm:"not null default '1' comment('收费模式 1:一次性收费 2:计时收费 9:其他') ENUM('1','2','9')" form:"chargemode"`
	PayMode                    string    `xorm:"not null default '2' comment('付费模式 1:先学后付；2:先付后学；9:其他') ENUM('1','2','9')" form:"paymode"`
	Price                      int       `xorm:"not null comment('金额 总价: chargemode=1时 小时单价: chargemode=2时') INT(11)" form:"price"`
	CalculatedPrice            float64   `xorm:"comment('计程价格') FLOAT(11,1)" form:"calculated_price"`
	TimingPrice                float64   `xorm:"comment('计时价格') FLOAT(11,1)" form:"timing_price"`
	Sub1money                  float64   `xorm:"comment('按科目收费科目一价格') FLOAT(11,1)" form:"sub1money"`
	Sub2money                  float64   `xorm:"comment('按科目收费科目2价格') FLOAT(11,1)" form:"sub2money"`
	Sub3money                  float64   `xorm:"comment('按科目收费科目3价格') FLOAT(11,1)" form:"sub3money"`
	Sub4money                  float64   `xorm:"comment('按科目收费科目4价格') FLOAT(11,1)" form:"sub4money"`
	ClassName                  string    `xorm:"not null comment('班型名称') VARCHAR(256)" form:"name"`
	UpdateTime                 time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
	RecordStatus               string    `xorm:"default '0' comment('备案状态 0:未备案 1:已备案') ENUM('0','1')"`
	Type                       int       `xorm:"default 0 comment('科目类型1-科目二 2-科目三') INT(1)"`
	Akaishi                    string    `xorm:"comment('上午开始') VARCHAR(255)" form:"akaishi"`
	Ajieshu                    string    `xorm:"comment('上午结束时间') VARCHAR(255)" form:"ajieshu"`
	Pkaishi                    string    `xorm:"comment('下午开始时间') VARCHAR(255)" form:"pkaishi"`
	Pjieshu                    string    `xorm:"comment('下午结束时间') VARCHAR(255)" form:"pjieshu"`
	Nkaishi                    string    `xorm:"comment('晚上开始时间') VARCHAR(255)" form:"nkaishi"`
	Njieshu                    string    `xorm:"comment('晚上结束时间') VARCHAR(255)" form:"njieshu"`
	Keshiduration              int       `xorm:"default 0 comment('课时间隔') INT(11)" form:"keshiduration"`
	Isopena                    int       `xorm:"default 1 comment('是否开启上午时段') INT(1)"`
	Isopenp                    int       `xorm:"default 1 comment('是否开启下午时段') INT(1)"`
	Isopenn                    int       `xorm:"default 1 comment('是否开启晚上时段') INT(1)"`
	Xiuxiriweek                string    `xorm:"comment('休息日设置') VARCHAR(20)" form:"xiuxiriweek"`
	Zhouqi                     int       `xorm:"comment('时段周期') INT(1)" form:"zhouqi"`
	Persnum                    int       `xorm:"comment('自定义预约人数') INT(11)" form:"persnum"`
	Isopenscoach               string    `xorm:"default '0' comment('是否开启跨班级选择教练') ENUM('0','1')"`
	Isopencoachtime            string    `xorm:"default '0' comment('是否开启教练自定义预约时段权限') ENUM('0','1')" form:"isopencoachtime"`
	Isopencoachperson          string    `xorm:"default '0' comment('是否开启教练自定义每课时预约人数权限') ENUM('0','1')"`
	Isopencoachsuject          int       `xorm:"default 0 comment('是否开启教练自定义科目权限') INT(11)"`
	Isopencomp                 int       `xorm:"default 0 comment('是否开启强制评价') INT(11)"`
	Baswage                    float32   `xorm:"comment('基本工资') FLOAT"`
	Meritpay                   float32   `xorm:"comment('绩效百分比  或 具体金额') FLOAT" form:"meritpay"`
	Favamount                  float32   `xorm:"comment('好评奖励金额') FLOAT(6,2)" form:"favamount"`
	Assamount                  float32   `xorm:"comment('差评惩罚金额') FLOAT(6,2)" form:"assamount"`
	Middamount                 float32   `xorm:"comment('中评惩罚') FLOAT(6,2)" form:"middamount"`
	DeleteStatus               string    `xorm:"VARCHAR(1)"`
	Isused                     string    `xorm:"VARCHAR(1)"`
	Appointments               string    `xorm:"comment('可以预约人数') VARCHAR(255)" form:"appointments"`
	Issetcoachtime             string    `xorm:"default '0' comment('是否允许 教练自定义上班时间  0 不允许 1允许') ENUM('0','1')" form:"issetcoachtime"`
	Timetrainingfee            int       `xorm:"comment('计时培训费用') INT(11)" form:"timetrainingfee"`
	Divisiontrainingfeeam      int       `xorm:"comment('分时段培训费上午') INT(11)" form:"divisiontrainingfeeam"`
	Divisiontrainingfeepm      int       `xorm:"comment('分时段培训费下午') INT(11)" form:"divisiontrainingfeepm"`
	Divisiontrainingfeeweek    int       `xorm:"comment('分时段培训费周六日') INT(11)" form:"divisiontrainingfeeweek"`
	Divisiontrainingfeenight   int       `xorm:"comment('分时段培训费晚上') INT(11)" form:"divisiontrainingfeenight"`
	Divisiontrainingfeeholiday int       `xorm:"comment('分时段培训费节假日') INT(11)" form:"divisiontrainingfeeholiday"`
}

type CharStandardInfo struct {
	Id                         int     `json:"id"`
	ClassName                  string  `json:"class_name"`
	PayMode                    string  `json:"pay_mode"`
	ChargeMode                 string  `json:"charge_mode"`
	TrainingMode               string  `json:"training_mode"`
	TrainingCarType            string  `json:"training_car_type"`
	Price                      int     `json:"price"`
	Timetrainingfee            int     `json:"timetrainingfee"`
	Akaishi                    string  `json:"akaishi"`
	Ajieshu                    string  `json:"ajieshu"`
	Pkaishi                    string  `json:"pkaishi"`
	Pjieshu                    string  `json:"pjieshu"`
	Nkaishi                    string  `json:"nkaishi"`
	Njieshu                    string  `json:"njieshu"`
	Keshiduration              int     `json:"keshiduration"`
	Zhouqi                     string  `json:"zhouqi"`
	Appointments               string  `json:"appointments"`
	Meritpay                   float32 `json:"meritpay"`
	Favamount                  float32 `json:"favamount"`
	Middamount                 float32 `json:"middamount"`
	Assamount                  float32 `json:"assamount"`
	Isopencoachtime            string  `json:"isopencoachtime"`
	Divisiontrainingfeeam      int     `json:"divisiontrainingfeeam"`
	Divisiontrainingfeepm      int     `json:"divisiontrainingfeepm"`
	Issetcoachtime             string  `json:"issetcoachtime"`
	Divisiontrainingfeeweek    int     `json:"divisiontrainingfeeweek"`
	Divisiontrainingfeenight   int     `json:"divisiontrainingfeenight"`
	Divisiontrainingfeeholiday int     `json:"divisiontrainingfeeholiday"`
	Xiuxiriweek                string  `json:"xiuxiriweek"`
	CalculatedPrice            float64 `json:"calculated_price"`
	TimingPrice                float64 `json:"timing_price"`
	Sub1money                  float64 `json:"sub_1_money"`
	Sub2money                  float64 `json:"sub_2_money"`
	Sub3money                  float64 `json:"sub_3_money"`
	Sub4money                  float64 `json:"sub_4_money"`
}

func (c *CharStandard) GetList(school_id int64, filter builder.Cond, pagesize int, offset int) (list []*CharStandardInfo, count int64, err error) {
	sess := engine.Table("dts_char_standard").Alias("dc").
		Where("dc.school_id=? and dc.isused=?", school_id, "1").
		And(filter).Desc("dc.id")
	if err = sess.Limit(pagesize, offset).Find(&list); err != nil {
		fmt.Println(err, "============================")
		return list, 0, err
	}
	_, err = engine.Table("dts_char_standard").Alias("dc").Select("count(dc.id) as count").
		Where("dc.school_id=? and dc.isused=?", school_id, "1").Get(&count)
	if err != nil {
		return list, count, err
	}
	return list, count, nil
}
